﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using test2_Calculator_wj.CalClasses;

namespace test2_Calculator_wj
{
    class Client
    {
        public String ClientSelected(String str)
        {
            string strA, strB, strbds, strysf;
            int ysf;//保存运算符在字符串中的位置
            double Result;

            strbds = str;

            if (strbds.Contains("+"))
            {
                ysf = strbds.IndexOf("+");
                strysf = "+";
            }
            else if (strbds.Contains("-"))
            {
                ysf = strbds.IndexOf("-");
                strysf = "-";
            }
            else if (strbds.Contains("*"))
            {
                ysf = strbds.IndexOf("*");
                strysf = "*";
            }
            else
            {
                ysf = strbds.IndexOf("/");
                strysf = "/";
            }

            strA = strbds.Substring(0, ysf);
            strB = strbds.Substring(ysf + 1);

            CalFactory toCalFacotry; ;
            Calculate toCal;
            switch (strysf)
            {
                case "+":
                    toCalFacotry = new PlusDAO();
                    toCal = toCalFacotry.Create();
                    strbds += "=" + toCal.Cal(strA, strB);
                    break;
                case "-":
                    toCalFacotry = new MinusDAO();
                    toCal = toCalFacotry.Create();
                    strbds += "=" + toCal.Cal(strA, strB);
                    break;
                case "*":
                    toCalFacotry = new MultiplyDAO();
                    toCal = toCalFacotry.Create();
                    strbds += "=" + toCal.Cal(strA, strB);
                    break;
                case "/":
                    toCalFacotry = new DivideDAO();
                    toCal = toCalFacotry.Create();
                    strbds += "=" + toCal.Cal(strA, strB);
                    break;
            }
            return strbds;
        }
    }
}
